/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javahomework04;

/**
 *
 * @author 朱荻 2010405121
 * 在网上看到这段代码 可以判断Email 很简洁 可惜看不懂 请老师讲解
 * public class Test {
public static void main(String[] args) {
String str = "asf@sf.com";
String regex = "^\\w*@[\\w\\d]*\\.\\w*$";
boolean isMatch = str.matches(regex);
System.out.println(isMatch);
}
}
 */
import java.io.*;

public class CheckEmail {

    public static void input() throws IOException {
        InputStream in1 = System.in;
        InputStreamReader in2 = new InputStreamReader(in1);
        BufferedReader in3 = new BufferedReader(in2);
        System.out.println("请输入E-mail:");
        String email = in3.readLine();

        boolean flag = true;
        for (int i = 0; i < email.length(); i++) {
            char c = email.charAt(i);
            int ch = (char) c;
            if (!((ch > 47 && ch < 58) || (ch > 63 && ch < 91) || (ch > 96 && ch < 123) || ch == 46)) {
                flag = false;
            }
        }
        int d=email.lastIndexOf('@');
        if (d==-1) {
            flag=false;
        }
        if (email.startsWith("@") || email.endsWith("@") || email.endsWith(".")) {
            flag = false;
        }
        if (flag) {
            System.out.println("您输入的E-mail:   " + email + "   是正确的!");
        } else {
            System.out.println("您输入的E-mail:   " + email + "   是错误的!");
        }
    }

    public static void main(String[] args) throws IOException {
        input();
    }
}
